package lanou.giftsay_01.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import de.hdodenhof.circleimageview.CircleImageView;
import lanou.giftsay_01.R;
import lanou.giftsay_01.bean.GongLueSreachBean;

/**
 * Created by dllo on 16/8/30.
 */
public class GlAdapter extends BaseAdapter {
    private GongLueSreachBean gongLueSreachBean ;
    private Context context ;
    private TextView textView;
    private ImageView imageView;
    private TextView view;
    private TextView titleTv;
    private TextView categoryTv;
    private TextView likeCountTv;
    public GlAdapter(Context context) {
        this.context = context;
    }

    public void setGongLueSreachBean(GongLueSreachBean gongLueSreachBean) {
        this.gongLueSreachBean = gongLueSreachBean;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return  gongLueSreachBean != null ? gongLueSreachBean.getData().getPosts().size():0;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.guidelistview_item , parent , false);
        }
        try {
            textView = (TextView) convertView.findViewById(R.id.select_item_tv);
            textView.setText(gongLueSreachBean.getData().getPosts().get(position).getTitle());
            imageView = (ImageView) convertView.findViewById(R.id.lv_iv);
            Picasso.with(context).load(gongLueSreachBean.getData().getPosts().get(position).getCover_image_url()).into(imageView);
            view = (TextView) convertView.findViewById(R.id.nickname_tv);
            view.setText(gongLueSreachBean.getData().getPosts().get(position).getAuthor().getNickname());
            titleTv = (TextView) convertView.findViewById(R.id.title_tv);
            titleTv.setText(gongLueSreachBean.getData().getPosts().get(position).getColumn().getTitle());
            CircleImageView mv = (CircleImageView) convertView.findViewById(R.id.avatar_iv);
            Picasso.with(context).load(gongLueSreachBean.getData().getPosts().get(position).getAuthor().getAvatar_url()).into(mv);
            categoryTv = (TextView) convertView.findViewById(R.id.tv_category);
            categoryTv.setText(gongLueSreachBean.getData().getPosts().get(position).getColumn().getCategory());
            likeCountTv = (TextView) convertView.findViewById(R.id.like_count_tv);
            likeCountTv.setText(String.valueOf(gongLueSreachBean.getData().getPosts().get(position).getLikes_count())
            );   } catch (NullPointerException e) {
            Log.d("MyLvadapter", "没有数据" + position);
        }
        return convertView;
    }


}
